#ifndef __W25QXX_H
#define __W25QXX_H

#include "main.h"
#include "spi.h"
#include "gpio.h"
#include "cmsis_os.h"

#define W25Q_CS_HIGH()	HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_SET);
#define W25Q_CS_LOW()	HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_RESET);


//TYPE
#define W25Q80 	0XEF13 	
#define W25Q16 	0XEF14
#define W25Q32 	0XEF15
#define W25Q64 	0XEF16
#define W25Q128	0XEF17
#define W25Q256 0XEF18

//指令表
#define W25X_WriteEnable		0x06 
#define W25X_WriteDisable		0x04 
#define W25X_ReadStatusReg1		0x05 
#define W25X_ReadStatusReg2		0x35 
#define W25X_ReadStatusReg3		0x15 
#define W25X_WriteStatusReg1    0x01 
#define W25X_WriteStatusReg2    0x31 
#define W25X_WriteStatusReg3    0x11 
#define W25X_ReadData			0x03 
#define W25X_FastReadData		0x0B 
#define W25X_FastReadDual		0x3B 
#define W25X_PageProgram		0x02 
#define W25X_BlockErase			0xD8 
#define W25X_SectorErase		0x20 
#define W25X_ChipErase			0xC7 
#define W25X_PowerDown			0xB9 
#define W25X_ReleasePowerDown	0xAB 
#define W25X_DeviceID			0xAB 
#define W25X_ManufactDeviceID	0x90 
#define W25X_JedecDeviceID		0x9F 
#define W25X_Enable4ByteAddr    0xB7
#define W25X_Exit4ByteAddr      0xE9

uint8_t w25q_spi_readWriteByte(uint8_t TxData);
void w25q_init(void);
uint8_t w25q_readSr(uint8_t regno);
void w25q_writeSr(uint8_t regno,uint8_t sr);
void w25q_waitBusy(void);
void w25q_writeEnable(void);
void w25q_writeDisable(void);
uint16_t w25q_readId(void);
void w25q_read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);
void w25q_writePage(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void w25q_writeNoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void w25q_eraseChip(void);
void w25q_eraseSector(uint32_t Dst_Addr);


#endif
